home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tjgold.zip / INSTALL.004 / FGUSER07.TXT < prev    next >
Text File  |  1995-05-29  |  15KB  |  371 lines

  1.                                   Calendars
  2.  
  3.                                     "A word fitly spoken is like apples
  4.                                      of gold in pictures of silver"
  5.                                                        Proverbs 25.11
  6.  
  7. Introduction
  8.  
  9.           The GOLDCAL unit contains Gold's calendaring support. With one
  10.      simple call to RunCalendar, you can add calendars to your
  11.      application. By default, Gold will display a single
  12.      month-at-a-glance calendar (see figure 7-1). The fussy developers
  13.      (e.g. Oregon inhabitants) can customize the calendar to meet their
  14.      specific needs. For example, the calendar can be displayed within a
  15.      larger window.
  16.  
  17.           If you are not familiar with Julian dates, you should consider
  18.      reading the introduction to Chapter 19.
  19.  
  20.  
  21.      Figure 7.1
  22.      A Month-at-a-Glance
  23.      Calendar
  24.  
  25.  
  26. Activating a Calendar Window
  27.  
  28.           To display a (modal) calendar in a pop-up window use the
  29.      RunCalendar command which is defined as follows:
  30.  
  31.      RunCalendar(StartDate:Dates;Tit:string):dates;
  32.  
  33.           Displays a month-at-a-glance calendar in a pop-up window. The
  34.      first parameter is the Julian date of any day in the month which is
  35.      to be displayed. The second argument is the window title. The
  36.      function returns the day that was highlighted when the window was
  37.      closed, or zero if the user presses Esc or clicks on the close
  38.      icon.
  39.  
  40.           If you want to display a fully functional calendar but don't
  41.      want to have a specific day highlighted, set the boolean variable
  42.      CalVars.ChooseDay to false.
  43.  
  44.  
  45.      Run the demo DEMCAL1.PAS to display a month-at-a-glance calendar.
  46.  
  47. Customizing the Calendar Icons and Keystrokes
  48.  
  49.           A user can easily change months and years by clicking on the 4
  50.      navigation icons. You can change the appearance of the icons by
  51.      modifying the following four character variables defined in
  52.      CalVars:
  53.  
  54.           CalVars.NextMchar - icon to move to next month
  55.           CalVars.PrevMchar - icon to move to previous month
  56.           CalVars.NextYchar - icon to move to next year
  57.           CalVars.PrevYchar - icon to move to previous year
  58.  
  59.           The corresponding keystrokes to change months and years are:
  60.      PgDn and PgUp to change months, Ctrl-PgDn and Ctrl-PgUp to change
  61.      years. These too can be customized by changing the following word
  62.      variables defined in CalVars:
  63.  
  64.           CalVars.NextMkey
  65.           CalVars.PrevMkey
  66.           CalVars.NextYkey
  67.           CalVars.PrevYkey
  68.  
  69.  
  70.           International users can modify the two character day strings
  71.      by editing the variable CalVars.DayLetters which is defined as
  72.      follows:
  73.  
  74.           CalVars.DayLetters := 'SuMoTuWeThFrSa';
  75.  
  76. Controlling the Calendar Colors
  77.  
  78.           You can customize the calendar display colors by modifying the
  79.      following elements of TINT using the function GoldSetColor:
  80.  
  81.           CalBorder
  82.           CalTitle
  83.           CalIcons
  84.           CalActiveMonth
  85.           CalEdgeMonth
  86.           CalToday
  87.           CalHiDay
  88.  
  89.  
  90.           The following code is an extract from DEMCAL2.PAS which
  91.      customizes the calendar colors:
  92.  
  93.           procedure CustomizeColors;
  94.           {}
  95.           begin
  96.              GoldSetColor(CalBorder,WhiteOnMagenta);
  97.              GoldSetColor(CalIcons,GreenOnMagenta);
  98.              GoldSetColor(CalTitle,YellowOnMagenta);
  99.              GoldSetColor(CalActiveMonth,YellowOnMagenta);
  100.              GoldSetColor(CalEdgeMonth,LightgrayOnMagenta);
  101.              GoldSetColor(CalToday,GreenOnMagenta);
  102.              GoldSetColor(CalHiday,LightMagentaOnBlack);
  103.           end; { CustomizeColors }
  104.  
  105.           The color used to display each day individually can be
  106.      customized using a calendar hook. This very flexible technique is
  107.      discussed later in the chapter.
  108.  
  109. Drawing a Plain Calendar
  110.  
  111.           One of the core routines used by the RunCalendar function is
  112.      DrawMonth, which draws a plain calendar without the icons. If you
  113.      want to draw a calendar for informational purposes, i.e. with no
  114.      input support, you can use DrawMonth, which is defined as follows:
  115.  
  116.      DrawMonth(Mon,Yr:word;X1,Y1:byte;Active:boolean):Dates;
  117.  
  118.           The first two word parameters identify the month and year
  119.      which is to be displayed. The next two byte parameters indicate the
  120.      position of the top left of the calendar. The final parameter
  121.      indicates whether the calendar should be drawn using the active
  122.      months colors, or the edge month colors. The function returns the
  123.      Julian date of the top left day in the seven by six day matrix.
  124.  
  125.      DrawMonth is used in the demo file DEMCAL7.PAS.
  126.  
  127. Customizing the Window Size
  128.  
  129.           By default, the window size is designed to be just large
  130.      enough to accommodate the monthly calendar. The window size,
  131.      however, can be made larger so that additional information may be
  132.      written to the window; such as a daily event log or a To Do list.
  133.  
  134.           To change the window size, modify the following CalVars
  135.      variables before calling RunCalendar: CalVars.WX1, CalVars.WY1,
  136.      CalVars.WX2, CalVars.WY2. These four variables define the total
  137.      dimensions of the calendar window. The position of the top left
  138.      corner of the calendar relative to the window is defined in the
  139.      following two variables: CalVars.CX1 and CalVars.CY1.
  140.  
  141.           Listed below is an extract from DEMCAL3.PAS which shows how
  142.      the window size and position can be customized:
  143.  
  144.           with CALVars do
  145.           begin
  146.             WX1 := 10;
  147.             WY1 := 5;
  148.             WX2 := 70;
  149.             WY2 := 20;
  150.             CX1 := 36;
  151.             CY1 := 1;
  152.           end;
  153.           MouseShow(true);
  154.           Answer := RunCalendar(TodayInJul,'A Big Calendar');
  155.  
  156. Using Calendar Hooks
  157.  
  158.           The RunCalendar function is designed to be easy to use, but
  159.      very flexible and customizable. The majority of the flexibility is
  160.      implemented in calendar hooks. There are three main hooks: a
  161.      character hook, a color hook and a change hook. If you are not
  162.      familiar with the principle of hooks in Gold, refer to the section
  163.      Understanding Hooks in Chapter 3.
  164.  
  165.           By using a combination of these hooks, you can create
  166.      sophisticated calendaring applications.
  167.  
  168. The Character Hook
  169.  
  170.           A character hook is a procedure which is called every time a
  171.      key is pressed or a mouse button is clicked. The hooked procedure
  172.      is called before the key is processed, i.e. before the character is
  173.      passed to RunCalendar for processing. The hook is particularly
  174.      useful for trapping special keys like F1 for help or Alt-N to
  175.      pop-up a set of notes.
  176.  
  177.           All you have to do is create a procedure following some
  178.      specific rules, and then call the AssignCalCharHook procedure to
  179.      instruct Gold to call your procedure every time a key is pressed.
  180.  
  181.           For a procedure to be eligible as a character hook it must
  182.      adhere to the following rules:
  183.  
  184.           The procedure must be declared as a far procedure at the root
  185.           level. Refer to the section Understanding Hooks in Chapter 3
  186.           for further information.
  187.  
  188.           The procedure must be declared with one variable parameter of
  189.           type word, and two variable parameters of type byte. These
  190.           parameters identify the user input, i.e. the Key, X and Y.
  191.  
  192.      The following procedure declaration follows these rules:
  193.  
  194.           {$F+}
  195.           procedure MyCalendarHook(var Code:word;var X,Y:byte);
  196.           begin
  197.              {some code}
  198.           end; {MyCalendarHook}
  199.           {$F-}
  200.  
  201.           The following procedure is then called to instruct Gold to
  202.      call your procedure after each calendar input:
  203.  
  204.      AssignCalCharHook(Hook:KeyPressedHook);
  205.  
  206.           Instructs Gold to call the specified procedure before
  207.      processing each user input to the calendar window.
  208.  
  209.           If subsequently, you want to remove the character hook,
  210.      execute the command RemoveCalCharHook.
  211.  
  212.           Run the demo programs DEMCAL4.PAS and DEMCAL6.PAS to see the
  213.      character hook in action.
  214.  
  215. The Color Hook
  216.  
  217.           The calendar color hook allows a program to customize the
  218.      display color of each day display on the calendar. Using this
  219.      feature an application might, for example, displays days with
  220.      appointments in one color and vacation days in another color.
  221.  
  222.           All you have to do is create a procedure following some
  223.      specific rules, and then call the AssignCalColorHook procedure to
  224.      instruct Gold to call your procedure every time a day is about to
  225.      be written to the window.
  226.  
  227.           For a procedure to be eligible as a color hook it must adhere
  228.      to the following rules:
  229.  
  230.           The procedure must be declared as a far procedure at the root
  231.           level. Refer to the section Understanding Hooks in Chapter 3
  232.           for further information.
  233.  
  234.           The procedure must be declared with one parameter of type
  235.           Dates, and one variable parameter of type byte. These
  236.           parameters identify the Julian date of the day to be drawn,
  237.           and the color which will be used to draw the day. The last
  238.           parameter, TheCol, is passed to the procedure with the value
  239.           that would be used if the hook were not in place.
  240.  
  241.      The following procedure declaration follows these rules:
  242.  
  243.           {$F+}
  244.           procedure ChangeFriSatSun(TheDay:Dates; var TheCol:byte);
  245.           {}
  246.           var DOW: byte;
  247.           begin
  248.              if TheCol = Tint[CalActiveMonth] then
  249.              begin
  250.                 DOW := DOWJul(TheDay);
  251.                 case DOW of
  252.                    5: TheCol := LightGreenOnBlue;
  253.                    0,6: TheCol := GreenOnBlue;
  254.                 end;
  255.              end;
  256.           end; { ChangeFriSatSun }
  257.           {$F-}
  258.  
  259.           The following procedure is then called to instruct Gold to
  260.      call your procedure after each calendar input:
  261.  
  262.      AssignCalColorHook(Hook:CalColorProc);
  263.  
  264.           Instructs Gold to call the specified procedure to determine
  265.      the color used to draw the day numbers in the calendar grille.
  266.  
  267.           If subsequently, you want to remove the color hook, execute
  268.      the command RemoveCalColorHook.
  269.  
  270.      Run the demo programs DEMCAL5.PAS to see the color hook in action.
  271.  
  272. The Change Hook
  273.  
  274.           The calendar change hook is designed for sophisticated
  275.      applications which want to update other parts of the display when
  276.      the user changes the active day or month on the calendar. For
  277.      example, a change hook could be used to display a list of the
  278.      selected day's appointments to the left of the calendar.
  279.  
  280.           All you have to do is create a procedure following some
  281.      specific rules, and then call the AssignCalChangeHook procedure to
  282.      instruct Gold to call your procedure every time a day is about to
  283.      be written to the window.
  284.  
  285.           For a procedure to be eligible as a change hook it must adhere
  286.      to the following rules:
  287.  
  288.           The procedure must be declared as a far procedure at the root
  289.           level. Refer to the section Understanding Hooks in Chapter 3
  290.           for further information.
  291.  
  292.           The procedure must be declared with one parameter of type
  293.           gCalChange, and two parameters of type longint. The first
  294.           parameter indicates the type of change that is about to occur.
  295.           The other two parameters represent dates; the specific date is
  296.           dependent upon the type of change.
  297.  
  298.  
  299.      The following procedure declaration follows these rules:
  300.  
  301.           {$F+}
  302.           procedure ChangeHook(CType:gCalChange;Val1,Val2:dates);
  303.           {}
  304.           begin
  305.              if CType = ChangeDay then
  306.              begin
  307.                 SelectedDay := Val2;
  308.                 ActivateBackground;
  309.                 WriteCenter(21,0,
  310.                 PadCenter(FancyDateStr(val2,true,true), 40,' '));
  311.                 ActivateTopWindow;
  312.                 WinDrawAll;
  313.              end;
  314.           end; { ChangeHook }
  315.           {$F-}
  316.  
  317.           The following procedure is then called to instruct Gold to
  318.      call your procedure after each calendar input:
  319.  
  320.      AssignCalChangeHook(Hook:CalChangeProc);
  321.  
  322.           Instructs Gold to call the specified procedure every time the
  323.      active month or day is changed, and when the window is repainted.
  324.  
  325.           If subsequently, you want to remove the color hook, execute
  326.      the command RemoveCalColorHook.
  327.  
  328. Understanding the Passed Parameters
  329.  
  330.           There are three different occasions when a change hook is
  331.      called: when the calendar window is repainted, when the visible
  332.      month is changed, and when the selected day is changed. The first
  333.      parameter passed to the hook procedure indicates which hook event
  334.      is occurring and is of type gCalChange.
  335.  
  336.      The enumerated type gCalChange is declared in GOLDCAL as follows:
  337.  
  338.           gCalChange = (Paint,ChangeDay,ChangeMonth);
  339.  
  340.           The meaning of the two Dates parameters is dependent upon the
  341.      value of the first parameter as follows:
  342.  
  343.           Paint - The first date is the active month and the second date
  344.      is the active year, e.g. 8 and 1995.
  345.  
  346.           ChangeDay - The first date is the old selected date and the
  347.      second parameter is the date which is about to become selected.
  348.      Both values represent the Julian date, e.g. 2449583 and 2449584.
  349.  
  350.           ChangeMonth - The first date is the active month and the
  351.      second date is the active year, e.g. 7 and 1996.
  352.  
  353.           The majority of applications will only use the ChangeDay
  354.      function, since this hook is called whenever the active day, month
  355.      or year is changed. Respond to the paint hook when an application
  356.      uses an enlarged window to write additional information (e.g. daily
  357.      appointments) to the non-calendar parts of the window. The contents
  358.      of the window should be refreshed when the paint message is
  359.      received.
  360.  
  361.      Run the demo programs DEMCAL6.PAS to see the change hook in action.
  362.  
  363.  
  364. Error Handling
  365.  
  366.           Since the calendar is displayed in a window, there is the
  367.      potential for an Out of Memory error. After calling RunCalendar, be
  368.      sure to call the function LastCalError to see if the calendar was
  369.      successfully displayed.
  370.  
  371.